package com.example.hospitaltraining.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.hospitaltraining.common.PageUtils;
import com.example.hospitaltraining.common.Query;
import com.example.hospitaltraining.mapper.UserMsgMapper;
import com.example.hospitaltraining.pojo.UserMsg;
import com.example.hospitaltraining.service.UserMsgService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class UserMsgServiceImpl extends ServiceImpl<UserMsgMapper, UserMsg> implements UserMsgService {
    @Override
    public PageUtils testpage(Map<String, Object> params) {
        String nickname = (String) params.get("name");
        String idCard = (String) params.get("idNumber");
        String auditStatus = (String) params.get("auditStatus");
        LambdaQueryWrapper<UserMsg> queryWrapper = new LambdaQueryWrapper<>();
        if(!StringUtils.isEmpty(nickname)&&!StringUtils.isEmpty(idCard)&&!StringUtils.isEmpty(auditStatus)){
            queryWrapper.and(item->{
                item.like(UserMsg::getName,nickname).or().like(UserMsg::getIdNumber,idCard).or().eq(UserMsg::getAuditStatus,auditStatus);
            });
        }else {
            if(!StringUtils.isEmpty(nickname)){
                queryWrapper.like(UserMsg::getName,nickname);
            }
            if(!StringUtils.isEmpty(idCard)){
                queryWrapper.like(UserMsg::getIdNumber,idCard);
            }
            if(!StringUtils.isEmpty(auditStatus)){
                queryWrapper.eq(UserMsg::getAuditStatus,auditStatus);
            }
        }

        IPage<UserMsg> pageInfo = this.page(
                new Query<UserMsg>().getPage(params),
                queryWrapper
        );
        return new PageUtils(pageInfo);
    }
}
